package com.uchedao.vehicledetection.view.baseinfo;

import android.app.Activity;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.uchedao.vehicledetection.R;
import com.uchedao.vehicledetection.activity.CaptureActivity;
import com.uchedao.vehicledetection.activity.ProvinceListActivity;
import com.uchedao.vehicledetection.db.DbHelper;
import com.uchedao.vehicledetection.global.GlobalInfo;
import com.uchedao.vehicledetection.inf.ICheckValueListener;
import com.uchedao.vehicledetection.inf.IOnResultBack;
import com.uchedao.vehicledetection.loadstate.UCheDaoRelativeLayout;
import com.uchedao.vehicledetection.model.Address;
import com.uchedao.vehicledetection.model.BaseInfo;
import com.uchedao.vehicledetection.model.CarTypeInfo;
import com.uchedao.vehicledetection.model.Draft;
import com.uchedao.vehicledetection.model.UseInfo;
import com.uchedao.vehicledetection.utils.CheckTextDateBtnValue;
import com.uchedao.vehicledetection.utils.CheckValueUtil;
import com.uchedao.vehicledetection.utils.ToastUtil;
import com.uchedao.vehicledetection.utils.Util;
import com.uchedao.vehicledetection.view.carlist.CarActivity;
import com.uchedao.vehicledetection.view.carlist.Entity.CarEntity;
import com.uchedao.vehicledetection.view.carlist.Entity.CarModel;
import com.uchedao.vehicledetection.view.carlist.Entity.IndexSelectItem;
import com.uchedao.vehicledetection.view.carlist.db.CarDbHelper;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;

/**
 * Description:基本信息——车辆信息
 * Date: 2015-09-18  14:14
 * User: wushan
 */
public class BaseInfoCarInfoView extends UCheDaoRelativeLayout implements IOnResultBack {


    private BaseInfo baseInfo;

    public static final int REQUEST_PROVINCE = 600;// 请求省份
    public static final int REQUEST_CITY = 601;// 市
    public static final int REQUEST_CAR_BRAND = 602;// 品牌
    public static final int REQUEST_CAR_SERIES = 603;// 系列
    public static final int REQUEST_CAR_MODEL = 604;// 车型
    public static final int REQUEST_SCAN = 605;// 扫描二维码ID

//    public static final int TYPE_PROVINCE = 605;// 省
//    public static final int TYPE_CITY = 606;// 市
//    public static final int TYPE_CAR_BRAND = 2;// 品牌
//    public static final int TYPE_CAR_SERIES = 3;// 系列
//    public static final int TYPE_CAR_MODEL = 4;// 车型

    public static final String KEY_TYPE = "carSelect";// 类型

    public static final String KEY_PROVINCE = "province";// 省份ID

    public static final String KEY_BRAND_ID = "brandId";// 品牌ID

    public static final String KEY_SERIES_ID = "seriesId";// 系列ID

    public static final String KEY_DATA = "data";// 返回的数据

    private String tempCarPLate;

    public BaseInfoCarInfoView(Context context) {
        super(context);
    }

    public BaseInfoCarInfoView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public BaseInfoCarInfoView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    public boolean save() {

        if (!Util.isCarPlateValid(tempCarPLate)) {
            ToastUtil.showToast("请输入有效车牌号", true);
            return false;
        } else {
            GlobalInfo.draft.car_plate = baseInfo.use_info.car_plate;
            GlobalInfo.dbHelper.updateDrafCarPlateByByInfoId(GlobalInfo.draft.info_number, tempCarPLate);
        }

        ContentValues values = new ContentValues();
        // values.put(DbHelper.KEY_BASE_INFO, baseInfo.toString());
        values.put(DbHelper.KEY_DRAFT_BASE_INFO, toJson(baseInfo));
        int status = baseInfo.getStatus();
        values.put(DbHelper.KEY_DRAFT_BASE_INFO_STATUS, status);

        // 保存成功
        if (GlobalInfo.dbHelper.updateDraf(GlobalInfo.draft.car_plate, values)) {
            GlobalInfo.draft.base_info = baseInfo.clone();
            GlobalInfo.draft.status[Draft.TYPE_BASE_INFO] = status;
            return true;
        }
        return false;
    }

    @Override
    public boolean dataChanged() {
        return !baseInfo.equals(GlobalInfo.draft.base_info);
//        return false;
    }

    @Override
    public void initDataBeforView() {
//        if (GlobalInfo.draft == null) {
//            GlobalInfo.draft = new Draft();
//        }
        baseInfo = GlobalInfo.draft.base_info.clone();
    }

    @Override
    public void initView() {

        UseInfo useInfo = baseInfo.use_info;
        CarTypeInfo carTypeInfo = baseInfo.car_type_info;

        LayoutInflater.from(mContext).inflate(R.layout.view_base_car_info, this);
        TextView subjectTv = (TextView) findViewById(
                R.id.base_car_info_title).findViewById(R.id.subject_tv);
        // 使用信息
        subjectTv.setText(R.string.base_use_info_subtitle);

        //车牌号
        CheckValueUtil.textEditListener(this, R.id.base_card_tv,
                R.id.base_card_et, GlobalInfo.draft.car_plate, new ICheckValueListener() {

                    @Override
                    public void getValue(View v, String str) {
                        tempCarPLate = str;
                        if (Util.isCarPlateValid(str)) {
                            baseInfo.use_info.car_plate = str;
                        } else {
                            ((EditText) v).setError(mContext.getString(R.string.card_ok_error));
                        }

                    }
                });

        // 生产厂商
//        CheckValueUtil.textEditListener(this, R.id.base_maker_tv,
//                R.id.base_maker_et, useInfo.maker_id, new ICheckValueListener() {
//
//                    @Override
//                    public void getValue(View v, String str) {
//                        baseInfo.use_info.maker_id = str;
//
//                    }
//                });
        // 行驶证型号
        CheckValueUtil.textEditListener(this,
                R.id.base_drive_book_type_tv, R.id.base_drive_book_type_et,
                useInfo.license_type, new ICheckValueListener() {

                    @Override
                    public void getValue(View v, String str) {
                        baseInfo.use_info.license_type = str;
                    }
                });
        // // 行驶证型号
        // CheckValueUtil.editListener(this,
        // R.id.base_drive_book_type_et,
        // useInfo.license_type, new ICheckValueListener() {
        //
        // @Override
        // public void getValue(View v, String str) {
        // baseInfo.use_info.license_type = str;
        // }
        // });

        // 注册地
        // 2015.9.24省市一体化
        // 监听是否显示星号 省市一体化
        CheckValueUtil.textBtnListener(this, R.id.base_reg_address_tv,
                R.id.base_reg_addr_province_bt, useInfo.province + " " + useInfo.city);

        Button base_reg_addr_province_bt = (Button) findViewById(R.id.base_reg_addr_province_bt);
        base_reg_addr_province_bt.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                startIndexSelectActivityForResult(REQUEST_PROVINCE, intent);
            }
        });


        // 监听是否显示星号
//        CheckValueUtil.textBtnListener(this, R.id.base_reg_address_tv,
//                R.id.base_reg_addr_city_bt, useInfo.city);
//        Button base_reg_addr_city_bt = (Button)
//                findViewById(R.id.base_reg_addr_city_bt);
//        base_reg_addr_city_bt.setOnClickListener(new OnClickListener() {
//
//            @Override
//            public void onClick(View v) {
//                if (baseInfo.use_info.province_id == -1)
//                    return;
//                Intent intent = new Intent();
////                intent.putExtra(KEY_TYPE,
////                        TYPE_CITY);
//                intent.putExtra(KEY_PROVINCE,
//                        baseInfo.use_info.province);
//                startIndexSelectActivityForResult(REQUEST_CITY, intent);
//
//            }
//        });

        // 车辆用途
        CheckValueUtil.textBtnListener(this, R.id.base_car_poperty_tv,
                R.id.base_car_poperty_bt, R.array.car_useful_strValues,
                useInfo.use_quality, new ICheckValueListener() {

                    @Override
                    public void getValue(View v, String str) {
                        baseInfo.use_info.use_quality = str;
                    }
                });

        // 保养情况
        CheckValueUtil.textBtnListener(this, R.id.base_keep_fit_tv,
                R.id.base_keep_fit_bt, R.array.keep_fit_strValues,
                useInfo.maintenance_at_4s, new ICheckValueListener() {

                    @Override
                    public void getValue(View v, String str) {
                        baseInfo.use_info.maintenance_at_4s = str;
                    }
                });


        // 品牌名称（）2015.9.24改成全称
        CheckValueUtil.textBtnListener(this, R.id.base_car_brand_tv,
                R.id.base_car_brand_bt, useInfo.brand_str + " " + useInfo.series_str + " " + useInfo.model_str);

        Button base_car_brand_bt = (Button) this
                .findViewById(R.id.base_car_brand_bt);
        base_car_brand_bt.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                startIndexSelectActivityForResult(REQUEST_CAR_BRAND, intent);

            }
        });

//        // 车系
//        Button base_car_series_bt = (Button) this
//                .findViewById(R.id.base_car_series_bt);
//        base_car_series_bt.setText(useInfo.series_str);
//        base_car_series_bt.setOnClickListener(new OnClickListener() {
//
//            @Override
//            public void onClick(View v) {
//                if (baseInfo.use_info.brand_id == -1)
//                    return;
//                Intent intent = new Intent();
//                intent.putExtra(KEY_TYPE,
//                        1);
//                intent.putExtra(KEY_BRAND_ID,
//                        baseInfo.use_info.brand_id);
//                startIndexSelectActivityForResult(REQUEST_CAR_SERIES, intent);
//
//            }
//        });
//
//        // 车型
//        // 监听是否显示星号
//        CheckValueUtil.textBtnListener(this, R.id.base_car_brand_tv,
//                R.id.base_car_model_bt, useInfo.model_str);
//        Button base_car_model_bt = (Button) this
//                .findViewById(R.id.base_car_model_bt);
//        base_car_model_bt.setOnClickListener(new OnClickListener() {
//
//            @Override
//            public void onClick(View v) {
//                if (baseInfo.use_info.brand_id == -1
//                        || baseInfo.use_info.series_id == -1)
//                    return;
//                Intent intent = new Intent();
//                intent.putExtra(KEY_TYPE,
//                        2);
//                intent.putExtra(KEY_SERIES_ID,
//                        baseInfo.use_info.series_id);
//                startIndexSelectActivityForResult(REQUEST_CAR_MODEL, intent);
//
//            }
//        });
//
//        // 校验车系车型
        checkSeriesModel();

        // 手动输入时显示
        LinearLayout base_car_model_input_layout = (LinearLayout) this
                .findViewById(R.id.base_car_model_input_layout);
        if ("手动输入".equals(useInfo.model_str)) {
            base_car_model_input_layout.setVisibility(View.VISIBLE);
        }
        // 手动输入车型信息
        // EditText base_car_model_et = (EditText) this
        // .findViewById(R.id.base_car_model_et);
        CheckValueUtil.textEditListener(this, R.id.base_car_model_et,
                R.id.base_car_model_et, useInfo.model_custom,
                new ICheckValueListener() {

                    @Override
                    public void getValue(View v, String str) {
                        baseInfo.use_info.model_custom = str;
                    }
                });

        // 车身颜色
        CheckValueUtil.textBtnListener(this, R.id.base_car_color_tv,
                R.id.base_car_color_bt, R.array.car_color_strValues,
                useInfo.color, new ICheckValueListener() {

                    @Override
                    public void getValue(View v, String str) {
                        baseInfo.use_info.color = str;
//                        EditText base_car_color_et = (EditText) findViewById(R.id.base_car_color_et);
//                        if (str.equals("自填")) {
//                            base_car_color_et.setVisibility(View.VISIBLE);
//                            base_car_color_et.setText("");
//                        } else {
//                            base_car_color_et.setVisibility(View.INVISIBLE);
//                        }
                    }
                });

        // 自填 车身颜色
//        EditText base_car_color_et = (EditText) this
//                .findViewById(R.id.base_car_color_et);
//        base_car_color_et.setVisibility(View.INVISIBLE);
//        CheckValueUtil.textEditListener(this, R.id.base_car_color_tv,
//                R.id.base_car_color_et, useInfo.color,
//                new ICheckValueListener() {
//
//                    @Override
//                    public void getValue(View v, String str) {
//                        baseInfo.use_info.color = str;
//                    }
//                });

        // 初登日期
        Button base_first_card_time_bt = (Button) this
                .findViewById(R.id.base_first_card_time_bt);
        CheckValueUtil.textDateBtnListener(
                CheckTextDateBtnValue.TYPE_YEAR_MONTH,
                CheckTextDateBtnValue.DATE_PAST, this,
                R.id.base_first_card_time_tv, R.id.base_first_card_time_bt,
                useInfo.card_time, new ICheckValueListener() {

                    @Override
                    public void getValue(View v, String str) {
                        baseInfo.use_info.card_time = str;

                        // 车龄
                        Button base_car_age_bt = (Button) findViewById(R.id.base_car_age_bt);
                        if (TextUtils.isEmpty(baseInfo.use_info.card_time))
                            base_car_age_bt.setVisibility(View.INVISIBLE);
                        else {
                            base_car_age_bt.setVisibility(View.VISIBLE);

                            try {// 计算车龄
                                base_car_age_bt.setText(getCoty(str));
                            } catch (ParseException e) {
                                e.printStackTrace();
                            }
                        }

                    }

                    private String getCoty(String str) throws ParseException {
                        Calendar nowCalendar = Calendar.getInstance();
                        int nowYear = nowCalendar.get(Calendar.YEAR);
                        int nowMonth = nowCalendar.get(Calendar.MONTH);

                        SimpleDateFormat formatter = new SimpleDateFormat(
                                "yyyy-MM");
                        Date date = formatter.parse(str);
                        Calendar calendar = Calendar.getInstance();
                        calendar.setTime(date);
                        int year = calendar.get(Calendar.YEAR);
                        int month = calendar.get(Calendar.MONTH);

                        int monthCount = (nowYear - year) * 12 + nowMonth
                                - month;

                        if (monthCount == 0)
                            return "小于一个月";
                        int y = monthCount / 12;
                        int m = monthCount % 12;

                        return (y > 0 ? y + "年" : "") + (m > 0 ? m + "月" : "");
                    }
                });

        // 使用性质
        CheckValueUtil.textBtnListener(this, R.id.base_use_poperty_tv,
                R.id.base_use_poperty_bt, R.array.car_use_property_strValues,
                useInfo.car_owner_type, new ICheckValueListener() {

                    @Override
                    public void getValue(View v, String str) {
                        baseInfo.use_info.car_owner_type = str;
                    }
                });

        // 车型信息
        TextView base_car_type_title = (TextView) findViewById(
                R.id.base_car_type_title).findViewById(R.id.subject_tv);
        base_car_type_title.setText(R.string.base_car_type_title);

        // 国产/进口
        CheckValueUtil.textBtnListener(this, R.id.base_import_flag_tv,
                R.id.base_import_flag_bt, R.array.made_in_entries,
                carTypeInfo == null ? "" : carTypeInfo.import_type,
                new ICheckValueListener() {

                    @Override
                    public void getValue(View v, String str) {
                        baseInfo.car_type_info.import_type = str;
                    }
                });

        // 排量
        CheckValueUtil.textEditListener(this, R.id.base_displace_tv,
                R.id.base_displace_et, carTypeInfo == null ? ""
                        : carTypeInfo.car_engines, new ICheckValueListener() {

                    @Override
                    public void getValue(View v, String str) {
                        baseInfo.car_type_info.car_engines = str;
                    }
                });

        // 排放标准
        CheckValueUtil.textBtnListener(this,
                R.id.base_displace_standard_tv, R.id.base_displace_standard_bt,
                R.array.displace_standard_strValues, carTypeInfo == null ? ""
                        : carTypeInfo.emission_standards,
                new ICheckValueListener() {

                    @Override
                    public void getValue(View v, String str) {
                        baseInfo.car_type_info.emission_standards = str;
                    }
                });

        // 发动机号
        CheckValueUtil.textEditListener(this, R.id.base_drive_num_tv,
                R.id.base_drive_num_et, carTypeInfo == null ? ""
                        : carTypeInfo.driver_number, new ICheckValueListener() {

                    @Override
                    public void getValue(View v, String str) {
                        baseInfo.car_type_info.driver_number = str;
                    }
                });

        // 变速型式
        CheckValueUtil.textBtnListener(this,
                R.id.base_change_speed_type_tv, R.id.base_change_speed_type_bt,
                R.array.change_speed_type_strValues, carTypeInfo == null ? ""
                        : carTypeInfo.trans_type, new ICheckValueListener() {

                    @Override
                    public void getValue(View v, String str) {
                        baseInfo.car_type_info.trans_type = str;
                    }
                });

        // 表显里程
        CheckValueUtil.textEditListener(this, R.id.base_kilometer_tv,
                R.id.base_kilometer_et, carTypeInfo == null ? ""
                        : carTypeInfo.kilometer, new ICheckValueListener() {

                    @Override
                    public void getValue(View v, String str) {
                        baseInfo.car_type_info.kilometer = str;
                    }
                });

        // 驱动方式
        CheckValueUtil.textBtnListener(this, R.id.base_drive_way_tv,
                R.id.base_drive_way_bt, R.array.drive_way_strValues,
                carTypeInfo == null ? "" : carTypeInfo.drive_type,
                new ICheckValueListener() {

                    @Override
                    public void getValue(View v, String str) {
                        baseInfo.car_type_info.drive_type = str;
                    }
                });

        // 二维码ID填写
        CheckValueUtil.textEditListener(this, R.id.base_checkid_tv,
                R.id.base_checkid_et,
                carTypeInfo == null ? "" : carTypeInfo.getCheckid(),
                new ICheckValueListener() {

                    @Override
                    public void getValue(View v, String str) {
                        baseInfo.car_type_info.setCheckid(str);
                    }
                });

        // 二维码扫描按钮
        findViewById(R.id.base_checkid_bt).setOnClickListener(
                new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        // 打开二维码扫描页面
                        ((Activity) mContext).startActivityForResult(new Intent(mContext, CaptureActivity.class), REQUEST_SCAN);
                    }
                });


    }

    @Override
    public void initDataAfterView() {

    }

    @Override
    public void initListener() {

    }

    /**
     * 启动选项
     *
     * @param requestCode
     */
    private void startIndexSelectActivityForResult(int requestCode, Intent intent) {

        switch (requestCode) {

            case REQUEST_PROVINCE:
                intent.setClass(mContext, ProvinceListActivity.class);
                break;
//            case REQUEST_CITY:
//                intent.setClass(mContext, CityListActivity.class);
//                break;
            case REQUEST_CAR_BRAND:
                intent.setClass(mContext, CarActivity.class);
                break;
            case REQUEST_CAR_SERIES:
                intent.setClass(mContext, CarActivity.class);
                break;
            case REQUEST_CAR_MODEL:
                intent.setClass(mContext, CarActivity.class);
                break;

        }


        ((Activity) mContext).startActivityForResult(intent, requestCode);

    }

    /**
     * 校正车系车型
     */
    private void checkSeriesModel() {
        // 如果车系尚未选择，跳出
        if (baseInfo.use_info.series_id == -1)
            return;
        ArrayList<CarModel> models = CarDbHelper.getCarModel(mContext,
                baseInfo.use_info.series_id);

        TextView base_car_brand_tv = (TextView) findViewById(R.id.base_car_brand_tv);
        // 若车型数量为0，则不显示车型按钮以及星号
        if (models.size() == 0) {
//            findViewById(R.id.base_car_model_bt).setVisibility(
//                    View.GONE);

            // 不显示星号
            base_car_brand_tv.setCompoundDrawablesWithIntrinsicBounds(
                    R.mipmap.read_star_no, 0, 0, 0);

        } else {
//            findViewById(R.id.base_car_model_bt).setVisibility(
//                    View.VISIBLE);

            // 如果车型数量不为0，且未有车型输入，则显示星号
            if (TextUtils.isEmpty(baseInfo.use_info.model_str))
                base_car_brand_tv.setCompoundDrawablesWithIntrinsicBounds(
                        R.mipmap.read_star, 0, 0, 0);
        }
    }

    public void onActivityResultView(int requestCode, int resultCode, Intent data) {
        System.out.println("ws----view中" + "requestCode = " + requestCode + " resultCode = " + resultCode);
        if (resultCode == Activity.RESULT_OK) {
            IndexSelectItem item = (IndexSelectItem) data
                    .getSerializableExtra(KEY_DATA);
            switch (requestCode) {
                case REQUEST_PROVINCE:
                    Address address = (Address) item;

                    // 保存省份ID
                    baseInfo.use_info.province_id = address.getProvince_id();
                    baseInfo.use_info.province = address.getProvince();

                    baseInfo.use_info.city_id = address.getCity_id();
                    baseInfo.use_info.city = address.getCity();

                    Button base_reg_addr_province_bt = (Button) findViewById(R.id.base_reg_addr_province_bt);
                    base_reg_addr_province_bt.setText(address.getProvince() + " " + address.getCity());

//                    ((Button) findViewById(R.id.base_reg_addr_city_bt)).setText("");// 重新设置省份后，城市为空
                    break;

//                case REQUEST_CITY:
//                    City city = (City) item;
//                    // 保存城市ID
//                    baseInfo.use_info.city_id = city.getId();
//                    baseInfo.use_info.city = city.getName();
//
//                    Button base_reg_addr_city_bt = (Button) findViewById(R.id.base_reg_addr_city_bt);
//                    base_reg_addr_city_bt.setText(city.getName());
//                    break;

                case REQUEST_CAR_BRAND:// 品牌
                case REQUEST_CAR_MODEL:
                case REQUEST_CAR_SERIES:

                    //保存品牌
                    CarEntity carEntity = (CarEntity) item;
                    baseInfo.use_info.brand_id = carEntity.getbId();
                    baseInfo.use_info.brand_str = carEntity.getbName();
//                    Button base_car_brand_bt = (Button) findViewById(R.id.base_car_brand_bt);
//                    base_car_brand_bt.setText(carEntity.getbName());

                    //保存车系
                    baseInfo.use_info.series_id = carEntity.getsId();
                    baseInfo.use_info.series_str = carEntity.getsName();

//                    ((Button) findViewById(R.id.base_car_series_bt))
//                            .setText(carEntity.getsName());

                    // 保存车型
                    baseInfo.use_info.model_id = carEntity.getmId();
                    baseInfo.use_info.model_str = carEntity.getmName();
//                    baseInfo.use_info.model_custom = null;

                    ((Button) findViewById(R.id.base_car_brand_bt)).setText(carEntity.getbName() + " " + carEntity.getsName() + " " + carEntity.getmName());
//                            .setText(carModel.getName());


//                    ((EditText) findViewById(R.id.base_car_model_et))
//                            .setText(null);
//
//                    if ("手动输入".equals(baseInfo.use_info.model_str)) {
//                        findViewById(R.id.base_car_model_input_layout)
//                                .setVisibility(View.VISIBLE);
//                    } else {
//                        findViewById(R.id.base_car_model_input_layout)
//                                .setVisibility(View.GONE);
//                    }

                    break;
//                    CarBrand carBrand = (CarBrand) item;
//                    // 保存品牌ID
//                    baseInfo.use_info.brand_id = carBrand.getId();
//                    baseInfo.use_info.brand_str = carBrand.getName();
//
//                    Button base_car_brand_bt = (Button) findViewById(R.id.base_car_brand_bt);
//                    base_car_brand_bt.setText(carBrand.getName());
//
//                    // 品牌重新设置后，车系、车型重新设置为空
//                    baseInfo.use_info.series_id = -1;
//                    baseInfo.use_info.series_str = null;
//                    baseInfo.use_info.model_id = -1;
//                    baseInfo.use_info.model_str = null;
//                    baseInfo.use_info.model_custom = null;
//
//                    ((Button) findViewById(R.id.base_car_series_bt))
//                            .setText(null);
//                    ((Button) findViewById(R.id.base_car_model_bt))
//                            .setText(null);
//                    ((EditText) findViewById(R.id.base_car_model_et))
//                            .setText(null);
//
//                    ((LinearLayout) findViewById(R.id.base_car_model_input_layout))
//                            .setVisibility(View.GONE);
//                    findViewById(R.id.base_car_model_bt)
//                            .setVisibility(View.VISIBLE);
//                    break;
//
//                case REQUEST_CAR_SERIES:
//                    CarSeries carSeries = (CarSeries) item;
//                    // 保存车系
//                    baseInfo.use_info.series_id = carSeries.getId();
//                    baseInfo.use_info.series_str = carSeries.getName();
//
//                    ((Button) findViewById(R.id.base_car_series_bt))
//                            .setText(carSeries.getName());
//
//                    // 车系重新设置后，车型重新设置为空
//                    baseInfo.use_info.model_id = -1;
//                    baseInfo.use_info.model_str = null;
//                    baseInfo.use_info.model_custom = null;
//                    ((Button) findViewById(R.id.base_car_model_bt))
//                            .setText(null);
//                    ((LinearLayout) findViewById(R.id.base_car_model_input_layout))
//                            .setVisibility(View.GONE);
//
//                    // 校验车系车型
//                    checkSeriesModel();
//
//                    break;
//
//                case REQUEST_CAR_MODEL:
//                    CarModel carModel = (CarModel) item;
//
//                    ((Button) findViewById(R.id.base_car_model_bt))
//                            .setText(carModel.getName());
//
//                    // 保存车型
//                    baseInfo.use_info.model_id = carModel.getId();
//                    baseInfo.use_info.model_str = carModel.getName();
//                    baseInfo.use_info.model_custom = null;
//
//                    ((EditText) findViewById(R.id.base_car_model_et))
//                            .setText(null);
//
//                    if ("手动输入".equals(baseInfo.use_info.model_str)) {
//                        findViewById(R.id.base_car_model_input_layout)
//                                .setVisibility(View.VISIBLE);
//                    } else {
//                        findViewById(R.id.base_car_model_input_layout)
//                                .setVisibility(View.GONE);
//                    }
//                    break;

                case REQUEST_SCAN:// 扫描二维码ID

                    String checkid = data.getStringExtra("scan_result");
                    baseInfo.car_type_info.setCheckid(checkid);
                    ((EditText) findViewById(R.id.base_checkid_et))
                            .setText(baseInfo.car_type_info.getCheckid());

                    break;
            }
        }

    }

}
